package com.ss.android.article.base.ui;

import android.content.Context;
import android.graphics.Canvas;
import android.text.Layout;
import android.text.SpannableStringBuilder;
import android.text.StaticLayout;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.TextView;
import android.widget.TextView;

public class EllipsisAppendSuffixTextView extends TextView {
    public interface a {
        void a();
    }

    public boolean a;
    public boolean b;
    private CharSequence c;
    private boolean d;
    private int e;
    private a f;

    public EllipsisAppendSuffixTextView(Context arg2) {
        super(arg2);
        this.a = false;
        this.d = false;
        this.b = false;
        this.e = 2147483647;
    }

    public EllipsisAppendSuffixTextView(Context arg2, AttributeSet arg3) {
        super(arg2, arg3);
        this.a = false;
        this.d = false;
        this.b = false;
        this.e = 2147483647;
    }

    public EllipsisAppendSuffixTextView(Context arg2, AttributeSet arg3, int arg4) {
        super(arg2, arg3, arg4);
        this.a = false;
        this.d = false;
        this.b = false;
        this.e = 2147483647;
    }

    private void a() {
        if (this.f != null) {
            this.f.a();
        }
    }

    protected void dispatchDraw(Canvas arg8) {
        String v0_3;
        CharSequence v6 = null;
        super.dispatchDraw(arg8);
        Layout v3 = this.getLayout();
        int v4 = v3.getLineCount();
        if (v4 <= 0) {
            this.a();
        } else {
            int v5 = v3.getEllipsisCount(v4 - 1);
            boolean v0 = v5 > 0 || v4 > this.e ? true : false;
            this.a = v0;
            if (v3 != null && this.c != null && this.c.length() > 0) {
                if ((v3 instanceof StaticLayout)) {
                    if (!this.a && !this.d) {
                        this.c = v6;
                        return;
                    }

                    int v0_1 = v3.getLineEnd(v4 - 1) - this.c.length() - v5;
                    CharSequence v3_1 = v3.getText();
                    if (!TextUtils.isEmpty(v3_1) && v0_1 <= v3_1.length() && v0_1 >= 0) {
                        CharSequence v0_2 = v3_1.subSequence(0, v0_1);
                        if (v0_2 == null) {
                            v0_3 = "";
                        } else {
                            v0_3 = v0_2 + "";
                        }

                        SpannableStringBuilder v3_2 = new SpannableStringBuilder(v0_3);
                        v3_2.append('…');
                        v3_2.append(this.c);
                        if (this.d) {
                            this.d = false;
                            this.b = true;
                        }

                        this.setText(((CharSequence) v3_2));
                        this.a();
                        return;
                    }

                    this.c = v6;
                    return;
                }

                this.a();
                return;
            }

            this.a();
        }
    }

    public void setAppendSuffix(CharSequence arg1) {
        this.c = arg1;
    }

    public void setDispatchDrawListener(a arg1) {
        this.f = arg1;
    }

    public void setForceEllipsis(boolean arg1) {
        this.d = arg1;
    }

    public void setMaxLines(int arg1) {
        super.setMaxLines(arg1);
        this.e = arg1;
    }

    public void setText(CharSequence arg3, TextView.BufferType arg4) {
        CharSequence v3;
        if (arg3 != null && arg3.length() > 0) {
            v3 = arg3 + " ";
        } else {
            v3 = arg3;
        }

        super.setText(v3, arg4);
    }
}

